
import request from '../utils/request'
import axios from 'axios'
import {useUserStore} from '@/stores'
const userStore = useUserStore()
// 添加合同
export const contrimAddSerive = (data)=>request.post('/contrim/add',data)

// 下载合同（带进度监控）
export const contrimRedownSerive = (file_id, progressCallback) => {
  const controller = new AbortController();
  const timeoutId = setTimeout(() => controller.abort(), 30000);
  
  return axios.get('/contrim/redown', {
    signal: controller.signal,
    params: { file_id },
    responseType: 'blob',
    headers: {
      'Content-Type': 'application/octet-stream',
      'Authorization': `Bearer ${userStore.token}`
    },
    onDownloadProgress: progressEvent => {
      if (progressEvent.total) {
        const percent = Math.round((progressEvent.loaded * 100) / progressEvent.total);
        progressCallback(percent);
      }
    }
  });
};
// 获取合同管理的列表
export const contrimGetListSerive = (params)=>request.get('/contrim/list',{params})
// 删除合同
export const contrimDeleteSerive = (file_id)=>request.post('/contrim/delete',{file_id})


// 更新下载次数
export const contrimUpdateClickSerive = (file_id)=>request.post('/contrim/update/click',{file_id})


